#-*- coding:utf-8 -*-
"""
@Time:2020/9/1816:00
@Auth:DaiXvWen
@File:project_methods.py
"""
from flask_sqlalchemy import request
from .models import *
class Project:
    def paging(self,page_size):
        #拿到页面参数
        page = request.args.get("page")
        #进行page判定
        if page is None:
            page = 1
        else:
            page = int(page)

        #使用paginate进行分页，一页10条数据
        page_size = page_size
        person_obj = Person.query.paginate(page, page_size)

        #拿到迭代后的多条对象
        # person_list = person_obj.items

        #页面栏显示五页，选中的一页排在中间，被显示被选中
        #如 1 2 ‘3’ 4 5
        #   3 4 ‘5’ 6 7
        #拿到总页数
        count_page=person_obj.pages
        #当总页数小于等于5时
        if count_page<=5:
            start=1
            end=person_obj.pages+1
            page_list = range(start, end)
        else:
            if page <= 3:
                start = 1
                end = start + 5
            elif page >= person_obj.pages - 2:
                start = person_obj.pages - 4
                end = person_obj.pages + 1
            else:
                start = page - 2
                end = page + 3
            page_list = range(start, end)  # 3  4 5 6 7

        return page_list